< previous page page_140 next page >

Page 140
Listing 5.22. continued
Private Sub vtxNumeric_NumericError(KeyAscii As Variant)
    '
    MsgBox "Enter Numeric data only! '0123456789.+-'"
    '
End Sub
Now save and run the test project. When you attempt to enter invalid data in the vtxDigits or the vtxNumeric boxes, you see the message box reminding you of the valid keystrokes for that control.
That ends the crash course on creating custom controls. The next three sections show you how to add other validation options to your VText control.
Adding Range-Checking Options to the VText Control
One of the other validation options you can add to the VText control is range checking. By adding min and max properties and a property to toggle the range checking on or off, along with a single validation method and an error event, you can expand the power of the VText control considerably.
Listing 5.23 shows the code you need to add to the general declaration section of the VText UserControl. These code declarations define the events, methods, and properties needed to add range checking to your custom control.
Type.gifListing 5.23. Declaring range-checking properties, events, and methods.
' --------------------------------------------------
' CheckRange values
'
' event list
Public Event InRangeError(vValue)
' Properties
Dim m_CheckRange As Boolean
Dim m_HighValue As Variant
Dim m_LowValue As Variant
' Default Values
Const m_def_CheckRange = 0
Const m_def_LowValue = 0
Const m_def_HighValue = 0

 
< previous page page_140 next page >

If you like this book, buy it!